﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Identity;
using Wuther.Infrastructure.Menus;
using Wuther.Infrastructure.Permissions;
using Wuther.Infrastructure.Users;

namespace Wuther.Infrastructure.Controllers.Users
{
    /// <summary>
    /// 用户扩展
    /// </summary>
    [RemoteService]
    [Area("Users")]
    [Route($"api/{InfrastructureRemoteServiceConsts.ModuleName}/users")]
    public class UsersController: InfrastructureController, IUsersAppService
    {
        private readonly IUsersAppService _service;

        public UsersController(IUsersAppService service)
        {
            _service = service;
        }
        /// <summary>
        /// 获取所有用户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("getAll")]
        [Authorize(IdentityPermissions.Users.Default)]
        public Task<List<UserOptionsDto>> GetAllUsers(GetAllUsersInput input)
        {
            return _service.GetAllUsers(input);
        }
        /// <summary>
        /// 获取所有用户信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("allUserInfo")]
        [Authorize(IdentityPermissions.Users.Default)]
        public Task<List<IdentityUserDto>> GetAllUsersInfoAsync(GetAllUsersInput input)
        {
            return _service.GetAllUsersInfoAsync(input);
        }
        /// <summary>
        /// 获取当前用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("currentUser")]
        [Authorize]
        public Task<CurrentUserInfo> GetCurrentUserAsync()
        {
            return _service.GetCurrentUserAsync();
        }

        /// <summary>
        /// 根据id获取用户
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("getById")]
        //[Authorize(IdentityPermissions.Users.Default)]
        public Task<UserInfoDto> GetUserInfoById(Guid Id)
        {
            return _service.GetUserInfoById(Id);
        }

        /// <summary>
        /// 获取用户头像
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("getAvatar")]
        //[Authorize(IdentityPermissions.Users.Default)]
        public Task<string> GetUserAvatarAsync(Guid? id)
        {
            return _service.GetUserAvatarAsync(id);
        }

        /// <summary>
        /// 设置用户头像
        /// </summary>
        /// <param name="id"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("setAvatar")]
        //[Authorize(IdentityPermissions.Users.Default)]
        public Task SetUserAvatarAsync(Guid? id, string url)
        {
            return _service.SetUserAvatarAsync(id, url);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userIds"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("getUsersByIds")]
        public Task<List<UserInfoDto>> GetUsersByIdsAsync(List<Guid> userIds)
        {
            return _service.GetUsersByIdsAsync(userIds);
        }


        [HttpGet]
        [Route("GetUserMenus")]
        public Task<List<MenuDto>> GetUserMenus()
        {
            return _service.GetUserMenus();
        }
    }
}
